﻿@using HTNResp.Model
<div class="row wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>
                适应症药物使用</h5>
            <div class="ibox-tools">
                <a class="btn btn-xs btn-primary" onclick="filter='';table.ajax.reload()">刷新</a>
                <a class="btn btn-xs btn-primary" onclick="createModelShow()">新建</a> <a class="btn btn-xs btn-primary"
                    onclick="SearchModelShow()">查询</a>
            </div>
        </div>
        <div class="ibox-content">
            <p id="ptest">
            </p>
            <table id="data_table" class="table table-bordered">
                <thead>
                    <tr>
                        <th style="width: 20%">
                            类名
                        </th>
                        <th style="width: 20%">
                            详细类名
                        </th>
                        <th style="width: 20%">
                            症状
                        </th>
                        <th style="width: 15%">
                            症状分类
                        </th>
                        <th style="width: 15%">
                            评估指南
                        </th>
                        <th style="width: 10%">
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!--新建窗口-->
<div class="modal inmodal fade" id="model_create" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">
                    新建</h4>
            </div>
            <div class="modal-body">
                <form id="frm_create" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        类名</label>
                    <div class="col-sm-10">
                        <select id="Create_GroupName" name="GroupName" placeholder="Enter email" class="form-control"
                            required>
                            <option value=""></option>
                            <option value="利尿剂">利尿剂</option>
                            <option value="β受体阻滞剂">β受体阻滞剂</option>
                            <option value="ARB">ARB</option>
                            <option value="ACEI">ACEI</option>
                            <option value="钙拮抗剂">钙拮抗剂</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        详细类名</label>
                    <div class="col-sm-10">
                        <select id="Create_GroupNameDetail" placeholder="详细类名" name="GroupNameDetail" class="form-control"
                            required>
                            <option></option>
                            <option>利尿剂抗醛固酮药</option>
                            <option>利尿剂袢利尿剂</option>
                            <option>利尿剂噻嗪类</option>
                            <option>β受体阻滞剂</option>
                            <option>ARB</option>
                            <option>ACEI</option>
                            <option>钙拮抗剂</option>
                            <option>钙拮抗剂二氢吡啶类</option>
                            <option>钙拮抗剂非二氢吡啶类</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状</label>
                    <div class="col-sm-10">
                        <input id="Create_Symptom" type="text" name="Symptom" class="form-control" required></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状分类</label>
                    <div class="col-sm-10">
                        <select id="Create_SymptomType" name="SymptomType" class="form-control" required>
                            <option value=""></option>
                            <option>适应症</option>
                            <option>可能性禁忌症</option>
                            <option>强制性禁忌症</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        评估指南</label>
                    <div class="col-sm-10">
                        <select id="Create_EvalGuidId" name="EvalGuidId" class="form-control" required>
                            <option value=""></option>
                            <option value="1">中国高血压防治指南2010</option>
                            <option value="2">中国国家基层管理指南2014</option>
                            <option value="3">2013ESH-ESC动脉高血压管理指南</option>
                        </select>
                    </div>
                </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">
                    关闭</button>
                <a type="submit" class="btn btn-primary" id="btn_add">
                    保存</a>
            </div>
        </div>
    </div>
</div>
<!--修改窗口-->
<div class="modal inmodal fade" id="model_Update" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">
                    修改</h4>
            </div>
            <div class="modal-body">
                <form id="frm_update" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                    </label>
                    <div class="col-sm-10">
                        <input id="Update_id" type="hidden" name="ID" class="form-control"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        类名</label>
                    <div class="col-sm-10">
                        <select id="Update_GroupName" name="GroupName" class="form-control" required>
                            <option value=""></option>
                            <option value="利尿剂">利尿剂</option>
                            <option value="β受体阻滞剂">β受体阻滞剂</option>
                            <option value="ARB">ARB</option>
                            <option value="ACEI">ACEI</option>
                            <option value="钙拮抗剂">钙拮抗剂</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        详细类名</label>
                    <div class="col-sm-10">
                        <select id="Update_GroupNameDetail" name="GroupNameDetail" placeholder="详细类名" class="form-control"
                            required>
                            <option></option>
                            <option>利尿剂抗醛固酮药</option>
                            <option>利尿剂袢利尿剂</option>
                            <option>利尿剂噻嗪类</option>
                            <option>β受体阻滞剂</option>
                            <option>ARB</option>
                            <option>ACEI</option>
                            <option>钙拮抗剂</option>
                            <option>钙拮抗剂二氢吡啶类</option>
                            <option>钙拮抗剂非二氢吡啶类</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状</label>
                    <div class="col-sm-10">
                        <input id="Update_Symptom" type="text" name="Symptom" class="form-control" required></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状分类</label>
                    <div class="col-sm-10">
                        <select id="Update_SymptomType" name="SymptomType" class="form-control" required>
                            <option value=""></option>
                            <option>适应症</option>
                            <option>可能性禁忌症</option>
                            <option>强制性禁忌症</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        评估指南</label>
                    <div class="col-sm-10">
                        <select id="Update_EvalGuidId" name="EvalGuidId" class="form-control" required>
                            <option value=""></option>
                            <option value="1">中国高血压防治指南2010</option>
                            <option value="2">中国国家基层管理指南2014</option>
                            <option value="3">2013ESH-ESC动脉高血压管理指南</option>
                        </select>
                    </div>
                </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">
                    关闭</button>
                <a type="button" class="btn btn-primary" id="btn_modify">
                    修改</a>
            </div>
        </div>
    </div>
</div>
<!--查找窗口-->
<div class="modal inmodal fade" id="model_Search" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">
                    查找</h4>
            </div>
            <div class="modal-body">
                <form role="form" id="frm_search" class="form-horizontal">
                @*<div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-10"><input id="Search_id" type="hidden" name="ID" class="form-control"></div>
                    </div>*@
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        类名</label>
                    <div class="col-sm-10">
                        <select id="Search_GroupName" name="GroupName" class="form-control">
                            <option value=""></option>
                            <option value="利尿剂">利尿剂</option>
                            <option value="β受体阻滞剂">β受体阻滞剂</option>
                            <option value="ARB">ARB</option>
                            <option value="ACEI">ACEI</option>
                            <option value="钙拮抗剂">钙拮抗剂</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        详细类名</label>
                    <div class="col-sm-10">
                        <select id="Search_GroupNameDetail" placeholder="Choose a Country..." name="GroupNameDetail"
                            class="form-control">
                            <option></option>
                            <option>利尿剂抗醛固酮药</option>
                            <option>利尿剂袢利尿剂</option>
                            <option>利尿剂噻嗪类</option>
                            <option>β受体阻滞剂</option>
                            <option>ARB</option>
                            <option>ACEI</option>
                            <option>钙拮抗剂</option>
                            <option>钙拮抗剂二氢吡啶类</option>
                            <option>钙拮抗剂非二氢吡啶类</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状</label>
                    <div class="col-sm-10">
                        <input id="Search_Symptom" type="text" name="Symptom" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        症状分类</label>
                    <div class="col-sm-10">
                        <select id="Search_SymptomType" name="SymptomType" class="form-control">
                            <option value=""></option>
                            <option>适应症</option>
                            <option>可能性禁忌症</option>
                            <option>强制性禁忌症</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        评估指南</label>
                    <div class="col-sm-10">
                        <select id="Search_EvalGuidId" name="EvalGuidId" class="form-control">
                            <option value=""></option>
                            <option value="1">中国高血压防治指南2010</option>
                            <option value="2">中国国家基层管理指南2014</option>
                            <option value="3">2013ESH-ESC动脉高血压管理指南</option>
                        </select>
                    </div>
                </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">
                    取消</button>
                <button type="button" class="btn btn-primary" onclick="SearchSubmit()">
                    查找</button>
            </div>
        </div>
    </div>
</div>
<!--删除窗口-->
@{
    List<EvalGuid> evalGridList = ViewBag.EvalGridId;
    List<string> evalGridListJs = new List<string>();
    foreach (EvalGuid eval in evalGridList)
    {
        evalGridListJs.Add("'" + eval.ID + "':'" + eval.GuidName + "'");
    }
    
}
@section script {
    <script>
    var evalGridList = {@Html.Raw(string.Join(",", evalGridListJs))};
    </script>
    <script>

        var filter = " ";
        var table = null;

        $.extend($.validator.messages, { required: '该项不能为空' });

        $(document).ready(function () {
            table = $("#data_table").DataTable({
                "pageLength": 10,
                "lengthChange": false,
                "processing": true,
                "serverSide": true,
                "ordering": false,
                "async": false,            //同步
                "dom": '<"html5buttons"B>Tgitp',
                "ajax": function (tdata, callback, settings) {
                    $.ajax({
                        type: "POST",       //类型
                        url: "/AdaptMedicineUse/AjaxList" + filter, //服务器地址
                        cache: false,
                        data: tdata,              //发送给服务器的数据
                        dataType: "json",
                        success: function (res) {              //成功时触发的执行函数
                            if (res.result == 0) {
                                toastr.warning("获取失败");
                            } else if (res.result == 100) {
                                location.href = "/Home/Index";
                            } else if (res.result == 300) {
                                location.href = "/Home/Illegal";
                            }
                            else {
                                callback(res.data);    //返回查询结果值
                            }
                        },
                        error: function (XMLHttpRequest, txtStatus, errorThrown) {  //失败时触发的执行函数
                            toastr.warning('查询失败，请重试');
                        }
                    });
                },
                "columns": [
                    { data: "GroupName" },
                    { data: "GroupNameDetail" },
                    { data: "Symptom" },
                    { data: "SymptomType" },
                    { data: "EvalGuidId",
                        "render": function (data, type, row) {
                            return evalGridList[data];
                        }
                    },
                    {
                        data: "ID",
                        "render": function (data, type, row) {
                            var html;
                            html = "<a class='btn btn-xs btn-primary' onclick='UpdateModelShow(" + data + ")'>修改</a>";
                            html += "&nbsp;<a class='btn btn-xs btn-danger'onclick='DeleteModelShow(" + data + ")' >删除</a>";
                            return html;
                        }
                    }
                ],
                "language": {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "每页显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "当前显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "当前显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "关键字搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
                "buttons": []
            })
            $("#frm_create").validate({});
            $("#frm_update").validate({});
        });



        //新建
        function createModelShow() {
            $("#model_create").modal('show');

        }

        var btn_add = $('#btn_add').ladda();
        btn_add.click(function () {
            btn_add.ladda('start');
            if (!$("#frm_create").valid()) {
                btn_add.ladda('stop');
                toastr.error("新建失败！");
                return false;
            }
            $.post("/AdaptMedicineUse/Create", $("#frm_create").serialize(), function (res) {
                btn_add.ladda('stop');
                if (res.result == 1) {
                    table.ajax.reload();
                    $("#model_create").modal('hide');
                    toastr.success("新建成功!");
                    $("#model_create").on("hidden.bs.modal", function () {
                        $("input,select").val("");
                    });
                } else if (res.result == 100) {
                    location.href = "/Home/Index";
                } else if (res.result == 300) {
                    location.href = "/Home/Illegal";
                } else {
                    toastr.error(res.msg);
                }
            })
        });
        

        //修改
        function UpdateModelShow(id) {
            $.post("/AdaptMedicineUse/Info/" + id, null, function (res) {
                if (res.result == 0) {
                    toastr.error("所选择项不存在,请刷新后重试");
                } else if (res.result == 100) {
                    location.href = "/Home/Index";
                } else if (res.result == 300) {
                    location.href = "/Home/Illegal";
                }
                else {
                    $("#Update_id").val(res.data.ID);
                    $("#Update_GroupName").val(res.data.GroupName);
                    $("#Update_GroupNameDetail").val(res.data.GroupNameDetail);
                    $("#Update_Symptom").val(res.data.Symptom);
                    $("#Update_SymptomType").val(res.data.SymptomType);
                    $("#Update_EvalGuidId").val(res.data.EvalGuidId);

                    $("#model_Update").modal('show');
                }
            })

        }

        var btn_modify = $('#btn_modify').ladda();
        btn_modify.click(function () {
            btn_modify.ladda('start');
            if (!$("#frm_update").valid()) {
                toastr.error("修改失败！");
                return false;
            }
            $.post("/AdaptMedicineUse/Create", $("#frm_update").serialize(), function (res) {
                btn_modify.ladda('stop');
                if (res.result == 1) {
                    table.ajax.reload();
                    $("#model_Update").modal('hide');
                    toastr.success("修改成功!");
                    $("#model_Update").on("hidden.bs.modal", function () {
                        $("input,select").val("");
                    });
                } else if (res.result == 100) {
                    location.href = "/Home/Index";
                } else if (res.result == 300) {
                    location.href = "/Home/Illegal";
                } else {
                    toastr.error(res.msg);
                }
            })
        });
        
        //删除
        function DeleteModelShow(id) {
            swal({
                title: "确定删除吗?",
                text: "删除后不可找回!",
                type: "warning",
                showCancelButton: true,
                cancelButtonText: "取消",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                closeOnConfirm: false
            }, function () {
                //表单提交
                $.post("/AdaptMedicineUse/Delete/?id=" + id, null, function (res) {
                    if (res.result == 0) {
                        swal("删除失败!", "没用可供删除的数据", "error");
                    } else if (res.result == 100) {
                        location.href = "/Home/Index";
                    } else if (res.result == 300) {
                        location.href = "/Home/Illegal";
                    }
                    else {
                        table.ajax.reload();
                        swal("已删除!", "此条信息已从数据库中移除", "success");
                    }
                })
                
            });

        }

        //查找
        function SearchModelShow() {

            $("#model_Search").modal('show');
        }

        function SearchSubmit() {
            // todo read input box and get filter string  
            filter = "?GroupName=" + $("#Search_GroupName").val() + "&GroupNameDetail=" + $("#Search_GroupNameDetail").val() + "&Symptom=" + $("#Search_Symptom").val() + "&SymptomType=" + $("#Search_SymptomType").val() + "&EvalGuidId=" + $("#Search_EvalGuidId").val();
            table.ajax.reload();
            $("#model_Search").modal('hide');
        }

    </script>
}
